package smilesnake.behavior_pattern.reflex;

import java.lang.reflect.InvocationTargetException;

public class ReflectServiceImpl2 {
	
	private String name;
	
	public ReflectServiceImpl2() {
		super();
	}

	public ReflectServiceImpl2(String name) {
		System.out.println(name);
		this.name = name;
	}

	public void sayHello() {
		System.err.println("Hello :" + this.name);
	}

	public ReflectServiceImpl2 getInstance() {
		ReflectServiceImpl2 object = null;
		try {
			object = (ReflectServiceImpl2) Class.forName("smilesnake.reflex.ReflectServiceImpl2").getConstructor(String.class).newInstance("张三");
		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) {
			ex.printStackTrace();
		}
		return object;
	}

	
	public static void main(String[] args){
		ReflectServiceImpl2 object = null;
		try {
			object = (ReflectServiceImpl2) Class.forName("smilesnake.reflex.ReflectServiceImpl2").getConstructor(String.class).newInstance("张三");
			object.sayHello();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
